import { NavBar } from "antd-mobile";
import PropTypes from "prop-types";
import React from "react";
import { useLocation, useNavigate, useSearchParams } from "react-router-dom";
const NavBarAgain = (props) => {
  let { title } = props;
  const navigate = useNavigate(),
    location = useLocation(),
    [usp] = useSearchParams();
  const handleBack = () => {
    let to = usp.get("to");
    if (location.pathname === "/login" && /^\/detail\/\d+$/.test(to)) {
      navigate(to, { replace: true });
      return;
    }
    navigate(-1);
  };
  return (
    <div>
      <NavBar onBack={handleBack}>{title}</NavBar>
    </div>
  );
};
// 不传props 给它赋一个默认值
NavBarAgain.defaultProps = {
  title: "个人中心",
};
//通过PropTypes对props做规则校验
NavBarAgain.propTypes = {
  title: PropTypes.string,
};
export default NavBarAgain;
